package com.baizhi.utils.spring;

import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.util.FileCopyUtils;

import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

public class FileCopyUtilsTest {

    @Test
    public void test1() throws Exception {
        // 获取类路径下的资源文件
        ClassPathResource resource = new ClassPathResource("files/1.txt");
        EncodedResource encodedResource = new EncodedResource(resource, StandardCharsets.UTF_8);
        // 文件复制
        String targetPath = "src/main/resources/files/2.txt";
        FileCopyUtils.copy(encodedResource.getInputStream(), new FileOutputStream(targetPath));
    }
}
